<div class="container-fluid" style="margin-top: 10px;">
    <div class="row">

        <div class="col-sm-12">
            <label>变动家具</label>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>家具编号</th>
                    <th>家具名称</th>
                    <th>隶属单位</th>
                    <th>所在学院</th>
                    <th>使用部门</th>
                    <th>领用人</th>
                    <th>当前状态</th>
                    <th>入账时间</th>
                </tr>
                </thead>
                <tbody>
                {volist name='furnList' id='vo'}
                <tr>
                    <td>{$vo.FURN_NO}</td>
                    <td>{$vo.FURN_NAME}</td>
                    <td>{$vo.BELONG}</td>
                    <td>{$vo.SHORTNAME}</td>
                    <td>{$vo.DEPART_SHORT}</td>
                    <td>{$vo.GET_PERSON}</td>
                    <td>{$vo.STATE}</td>
                    <td>{$vo.ENTER_TIME}</td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>

        {php}
        $alterType = \app\index\controller\Dict::getFurnAlterType();
        {/php}

        <div class="col-sm-12">
            <label>变动表单</label>
            <div class="col-sm-12" style="border: 1px solid #ddd;padding: 10px 0px">
                <form id="alterForm" method="post" action="addAlter">
                    <input hidden name="furnIds" value="{$furnIds}">
                    {:form('select',['title'=>'变动类型','name'=>'ALTERTYPE_ID','list'=>$alterType,'key'=>'ALTER_TYPE_ID','field'=>'ALTER_TYPE','col'=>'col-sm-6'])}
                    {:form('text',['title'=>'变动时间','name'=>'ALTER_TIME','col'=>'col-sm-6'])}
                    {:form('text',['title'=>'经手人','name'=>'CHECK_PERSON','col'=>'col-sm-6'])}
                    {:form('text',['title'=>'负责人','name'=>'CHARGE_PERSON','col'=>'col-sm-6'])}
                    <div id="allocate" style="display: none">
                    {:form('depart',['c_title'=>'调拨至学院','c_col'=>'col-sm-6','b_title'=>'部门','b_name'=>'DEPART_ID','b_col'=>'col-sm-6'])}
                    </div>
                    <div id="reject" style="display: none">
                    {:form('text',['title'=>'报废去向','name'=>'DISPOSE_DIRECT','col'=>'col-sm-6'])}
                    </div>
                    {:form('text',['title'=>'备注','name'=>'REMARK','col'=>'col-sm-12'])}
                    {:line()}
                    {:form('text',['title'=>'制单人','disable'=>'disabled','value'=>$Think.session.user_name,'col'=>'col-sm-6'])}
                    {:form('text',['title'=>'制单时间','disable'=>'disabled','value'=>date('Y-m-d'),'col'=>'col-sm-6'])}
                </form>
            </div>
        </div>

        <div class="col-sm-12" style="margin-top: 10px;text-align: center">
            <button id="submit" class="btn btn-info">确认变更</button>
        </div>
    </div>
</div>

<script>

    $(function () {

        $("[name='ALTER_TIME']").flatpickr({maxDate:new Date()});

        $("[name='ALTERTYPE_ID']").on('change',function () {
            var type = $("[name='ALTERTYPE_ID']").val();
            if(type == '01'){
                $("#allocate").show();
                $("#reject").hide();
            }
            else{
                $("#allocate").hide();
                $("#reject").show();
            }
        });

        $("#submit").on('click',function () {
            layer.confirm('确认执行变更吗？',function (index) {
                layer.close(index);
                layer.load();
                $("#alterForm").ajaxSubmit(function (text) {
                    console.log(text);
                    layer.closeAll('loading');
                    var json = JSON.parse(text);
                    if(json['code']=='200'){
                        layer.alert(json['msg'],{icon:1},function (index) {
                            layer.close(index);
                            parent.location.reload();
                        });
                    }
                    else{
                        layer.alert(json['msg'],{icon:2});
                    }
                });
            });
        });
    });


</script>